package com.sugar.real.estate.module.business.controller.app.info;

import com.sugar.real.estate.framework.common.pojo.CommonResult;
import com.sugar.real.estate.framework.common.pojo.PageResult;
import com.sugar.real.estate.module.business.controller.app.info.vo.AppInfoPageReqVO;
import com.sugar.real.estate.module.business.controller.app.info.vo.AppInfoRespVO;
import com.sugar.real.estate.module.business.service.info.InfoService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.annotation.security.PermitAll;
import javax.validation.Valid;

import java.util.List;

import static com.sugar.real.estate.framework.common.pojo.CommonResult.success;

@Tag(name = "APP - 资讯信息")
@RestController
@RequestMapping("/biz/info")
@Validated
public class AppInfoController {

    @Resource
    private InfoService infoService;

    @GetMapping("/get")
    @Operation(summary = "获得资讯信息")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PermitAll
    public CommonResult<AppInfoRespVO> getInfo(@RequestParam("id") Long id) {
        return success(infoService.appGetInfo(id));
    }

    @GetMapping("/page")
    @Operation(summary = "获得资讯信息分页")
    @PermitAll
    public CommonResult<PageResult<AppInfoRespVO>> getInfoPage(@Valid AppInfoPageReqVO pageReqVO) {
        return success(infoService.appGetInfoPage(pageReqVO));
    }

    @GetMapping("/hot")
    @Operation(summary = "获得热门资讯")
    @PermitAll
    public CommonResult<List<AppInfoRespVO>> getHotList() {
        return success(infoService.getHotList());
    }
}